package com.autonomous_printer.util;


import com.autonomous_printer.pojo.Order;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 订单工具
 */
@Component
public class OrderUtil {

    /**
     * 可以通过订单号查到支付地址
     * string  订单号
     * string  支付地址
     */
    private Map<Integer, Order> table = new ConcurrentHashMap<>();


    public boolean put(int id, Order order) {
        try {
            table.put(id, order);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public Order get(Integer id) {
        return table.get(id);
    }

    public boolean contains(Integer id) {
        return table.containsKey(id);
    }

    public boolean remove(Integer id) {
        if (contains(id)) {
            table.remove(id);
        }
        return true;
    }

}
